#include <iostream>
using namespace std;

class A {
public:
	A (void) {
		cout << "A::A(void)" << endl;
	}
	A (const A& that) {
		cout << "A::A(const A& that)" << endl;
	}
};

void foo(A a) {}

A bar (void) {
	A a; //A:A(void)
	cout << "bar::a=" << &a << endl;
	return a;
}
int main (void)
{
	A a1; //A::A(void)
	//A a2(a1);//A::A(const A& that)
	A a2 = a1;//A::A(const A& that)
	foo (a1); //A::A(const A& that) A a = a1;
	//正常bar返回a拷贝到临时对象中, 临时对象再拷贝到a3
	//发生两次拷贝构造,因为编译器的优化,直接让a3引用a 
	A a3 = bar ();//A::A(const A& that)//直接优化了  tmp =a;A a3= tmp ;A a3 = a;
	cout << "main::a3=" << &a3 << endl;
	return 0;
}
